from app.Models.Model import BmProject
from app import dBSession
import time

class ProjectService:
    """
        项目服务层
    """
    def add(self, email, user_id, project_id):
        """
        添加
        @param: string  data
        @param: integer type
        @param: integer level
        @retrun integer boolean
        """
        data = {
            'email': email,
            'user_id': user_id,
            'project_id': project_id,
            'create_time': int(time.time())
        }
        try:
            log = BmProject(**data)
            dBSession.add(log)
            dBSession.flush()
            id = log.id
            dBSession.commit()
            return id
        except  Exception as e:
            dBSession.rollback()
            return 0